/*
 * AddRemainReminder.java
 *
 * Created on 2008年6月9日, 上午12:39
 */

package gui;

import abstractmodel.IAccount;
import abstractmodel.IUser;
import reminder.RemainReminder;

/**
 *
 * @author  littlechild
 */
public class AddRemainReminder extends javax.swing.JPanel {
    
    IUser ownUser;
    IAccount ownAccount;
    /** Creates new form AddRemainReminder */
    public AddRemainReminder(IUser user,IAccount account) {
        ownUser=user;
        ownAccount=account;
        initComponents();
        initMode();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelAccountName = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxType = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldLine = new javax.swing.JTextField();
        jButtonConfirm = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel1.setText("添加帐户余额提醒：");

        jLabel2.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel2.setText("帐户：");

        jLabelAccountName.setFont(new java.awt.Font("宋体", 0, 14));

        jLabel3.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel3.setText("提醒方式：");

        jComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel4.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel4.setText("金额提醒线：");

        jButtonConfirm.setText("确定");
        jButtonConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmActionPerformed(evt);
            }
        });

        jButtonCancel.setText("取消");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelAccountName, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxType, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldLine, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(jButtonConfirm)
                        .addGap(120, 120, 120)
                        .addComponent(jButtonCancel)))
                .addContainerGap(83, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabelAccountName, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jLabel4)
                .addGap(27, 27, 27)
                .addComponent(jTextFieldLine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(65, 65, 65)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonConfirm)
                    .addComponent(jButtonCancel))
                .addContainerGap(97, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmActionPerformed
        // TODO add your handling code here:
            if (this.jTextFieldLine.getText().equals("")) {
                String[] options = {"确定"};
                    javax.swing.JOptionPane.showOptionDialog(null, "金额提醒线未填！", 
                        "警告", javax.swing.JOptionPane.DEFAULT_OPTION, 
                        javax.swing.JOptionPane.WARNING_MESSAGE, null, options, options[0]); 
                 return;
            }

            int selectType = 0;
            if (this.jComboBoxType.getSelectedIndex() == 1)
                selectType = 1;
            RemainReminder reminder = new RemainReminder(
                    ownUser.getUserInfo().getValue("用户名").getString(), this.ownAccount.getAccountInfo().getid());
            reminder.setReminderMode(selectType);
            Double d = new Double(this.jTextFieldLine.getText());
            reminder.setThreshold(d);
            Main.reminderClient.addReminder(reminder);
            jButtonCancelActionPerformed(evt);
    }//GEN-LAST:event_jButtonConfirmActionPerformed

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        // TODO add your handling code here:
        Utilities.cancelDialog(this);
    }//GEN-LAST:event_jButtonCancelActionPerformed
    
    private void initMode() {
        this.jLabelAccountName.setText(ownAccount.getAccountInfo().getValue("帐户名称").getString());
        jComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "以窗口方式提醒", "以邮件方式提醒" }));
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonConfirm;
    private javax.swing.JComboBox jComboBoxType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabelAccountName;
    private javax.swing.JTextField jTextFieldLine;
    // End of variables declaration//GEN-END:variables
    
}
